package com.lyj.common.core.domain;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2025-08-17
 * Time: 22:29
 */

import com.lyj.common.core.enums.ResultCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * 表格分页数据对象
 */
@Getter
@Setter
@NoArgsConstructor
public class TableDataInfo {
    //总记录数
    private long total;
    //列表数据
    private List<?> rows;
    //消息状态码
    private int code;
    //消息内容
    private String msg;

    /**
     * 查出列表没有任何数据时调用
     * @return
     */
    public static TableDataInfo empty(){
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(ResultCode.SUCCESS.getCode());
        tableDataInfo.setMsg(ResultCode.SUCCESS.getMsg());
        tableDataInfo.setRows(new ArrayList<>());
        tableDataInfo.setTotal(0);
        return tableDataInfo;
    }

    /**
     * 查出数据时调用
     * @return
     */
    public static TableDataInfo success(List<?> list,long total){
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(ResultCode.SUCCESS.getCode());
        tableDataInfo.setMsg(ResultCode.SUCCESS.getMsg());
        tableDataInfo.setRows(list);
        tableDataInfo.setTotal(total);
        return tableDataInfo;
    }
}
